package com.example.mybatisstudy.controller;

import com.example.mybatisstudy.mapper.UserMapper;
import com.example.mybatisstudy.model.Userinfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/user")
public class UserController {

    private static final Map map = new HashMap<>();

    @Autowired
    private UserMapper userMapper;

    @RequestMapping("/add")
    public Object add(Userinfo user){
        int num = userMapper.insert(user);
        return map;
    }

    @RequestMapping("/update")
    public Object update(Userinfo user){
        int num = userMapper.update(user);
        return map;
    }

    @RequestMapping("/queryUserWithArticle")
    public Object queryUserWithArticle(){
        return userMapper.queryUserWithArticle();
    }

    @RequestMapping("/queryByUser")
    public Object queryByUser(Userinfo userinfo){
        return userMapper.queryByUser(userinfo);
    }

    @RequestMapping("/deleteByIds")
    public Object deleteByIds(@RequestParam List<Integer> ids){
        int num = userMapper.deleteByIds(ids);
        return map;
    }
}
